<template>
  <div>
    <div>
      <FormPanel ref="formPanel" :list="formList" :cols="2" :labelWidth="150" :formType="type" :isSubmitBtn="false" @formChange="formChangeHandle" />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button v-if="optTypes != 'detail'" type="primary" @click="saveDrawer">确&nbsp;&nbsp;定</el-button>
      <el-button  @click="closeDrawer">关&nbsp;&nbsp;闭</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import {
  getCompalaintById
} from '@/api/customerRepair/customerComplaint/customerComplaintMng';
import { IDNumber, phone, numberCheck, email } from '@/utils/validate';
import moment from 'moment';
export default {
  components: {

  },
  mixins: [dictionary],
  props: {
    excuteComplaintId: Number,
    excuteComplaintNo: String,
    excuteComplaintVin: String,
    optTypes: String
  },
  data() {
    this.saveData = {};
    return {
      vinData:{},

      formList: this.createFormList(),
      flag: false,
      type: null,
      customerComplaint: {
        complaintId: ''
      }
    };
  },
  created() {},
  mounted() {
    this.getCompalaintExcute();
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '投诉单编号',
          fieldName: 'complaintNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'vin',
          disabled: true
        },
        {
          type: 'DATE_TIME',
          label: '回访时间',
          fieldName: 'recallDate',
          disabled: (this.optTypes == 'detail'),
          rules: [{ required: !(this.optTypes == 'detail'), message: '请填写回访时间', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '回访人',
          fieldName: 'recallMan',
          disabled: (this.optTypes == 'detail')
        },
        {
            type: 'TEXT_AREA',
            label: '客户反馈',
            // fieldName: 'recallContent',
            // 回显字段调整
            fieldName: 'usertxt',
            selfCols: 2,
            maxlength: 500,
            disabled: (this.optTypes == 'detail')
        },
        {
          type: 'SELECT',
          label: '投诉结果',
          fieldName: 'result',
          itemList: this.createDictList('8205'),
          disabled: this.optTypes == 'detail',
          rules: [{ required: !(this.optTypes == 'detail'), message: '请选择投诉结果', trigger: 'change' }]
        },
        {
            type: 'TEXT_AREA',
            label: '作废原因',
            fieldName: 'deletereason',
            selfCols: 2,
            maxlength: 500,
            disabled: (this.optTypes == 'detail')
        },
        {
          type: 'SELECT',
          label: '用户最终情绪',
          fieldName: 'attitude2',
          itemList: [
            {text: "非常满意", value: "1"},
            {text: "比较满意", value: "2"},
            {text: "一般满意", value: "3"},
            {text: "比较不满意", value: "4"},
            {text: "非常不满意", value: "5"}
          ],
          disabled: (this.optTypes == 'detail'),
          rules: [{ required: !(this.optTypes == 'detail'), message: '请选择用户最终情绪', trigger: 'change' }]
        }
      ];
    },
    formChangeHandle(val) {
      this.flag = true;
      this.saveData = val;
    },
    async getCompalaintExcute() {
      if(this.excuteComplaintId){
        const res = await getCompalaintById(this.excuteComplaintId);
        if (res.resultCode != 200) {
          this.$message.error('查询客户投诉详情失败');
          return;
        }
        this.customerComplaint = res.data;
        this.formList.forEach(x => {
          x.initialValue = this.customerComplaint[x.fieldName];
        });
      }else{
        this.formList.find(item => item.fieldName === 'vin').initialValue = this.excuteComplaintVin;
        this.formList.find(item => item.fieldName === 'complaintNo').initialValue = this.excuteComplaintNo;
      }
      this.formList = [...this.formList];
    },
    closeDrawer() {
      this.$emit('cancle',this.flag);
    },
    async saveDrawer() {
      this.$refs.formPanel.SUBMIT_FORM();
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.flag) {
        this.$emit('reqReturn',this.saveData);
      }
    }
  }
};
</script>
